from pydantic import BaseModel
from typing import Optional, List
from datetime import datetime

class TagBase(BaseModel):
    id: int
    name: str

    class Config:
        from_attributes = True

class ArticleBase(BaseModel):
    title: str
    content: str
    status: str = 'draft'

class ArticleCreate(ArticleBase):
    tags: List[int] = []  # 文章关联的标签ID列表

class ArticleUpdate(BaseModel):
    title: Optional[str] = None
    content: Optional[str] = None
    status: Optional[str] = None
    tags: Optional[List[int]] = None  # 更新的标签ID列表

class Article(ArticleBase):
    id: int
    author_id: int
    created_at: datetime
    updated_at: datetime
    view_count: int
    is_deleted: bool
    tags: List[TagBase] = []  # 返回给前端的标签信息

    class Config:
        from_attributes = True